package com.atguigui.leetcode;

/**
 * 1758.生成交替二进制字符串的最少操作数
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/11/29 16:55
 */
public class P1758MinimumChangesToMakeAlternatingBinaryString {

    public static void main(String[] args) {
        Solution solution = new P1758MinimumChangesToMakeAlternatingBinaryString().new Solution();
        // TO TEST
        System.out.println(solution.minOperations("0100"));
    }

    class Solution {
        public int minOperations(String s) {
            int cnt = 0;
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                // '0' = 48
                if (c != (char) ('0' + i % 2)) {
                    cnt++;
                }
            }
            //cnt => 以0开头的
            //s.length() - cnt =>  以1开头
            return Math.min(cnt, s.length() - cnt);
        }
    }

}
